package com.dm.shop.config;

import com.google.gson.Gson;
import com.qiniu.common.Zone;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version 1.0
 * @author: Saiya Wang
 * @desc: 七流云上传配置
 * @date: 2021/7/24 11:23
 */
@Configuration
public class QiniuUploadFileConfig {
    /**
     * 华南 配置自己空间所在区域
     *
     */
    @Bean
    public com.qiniu.storage.Configuration qiniuConfig()
    {
        return new com.qiniu.storage.Configuration(Zone.huanan());
    }

    /**
     * 构建七牛上传工具示例
     *
     */
    @Bean
    public UploadManager uploadManager()
    {
        return new UploadManager(qiniuConfig());
    }

    /**
     * 配置个人账号密钥
     */
    @Value("${qiniu.AccessKey}")
    private String accessKey;

    @Value("${qiniu.SecretKey}")
    private String secretKey;

    /**
     * 认证信息实例
     */
    @Bean
    public Auth auth()
    {
        return Auth.create(accessKey,secretKey);
    }

    /**
     * 构建七牛空间管理实例
     */
    @Bean
    public BucketManager bucketManager()
    {
        return new BucketManager(auth(),qiniuConfig());
    }

    @Bean
    public Gson gson()
    {
        return new Gson();
    }
}
